﻿// ConsoleApplication1.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>
#include<vector>
#include<list>
#include<deque>
#include<algorithm>
#include<map>

using namespace std;

//bool searchVal(vector<int>::iterator beg, vector<int>::iterator end, int val){
//	bool flag = 0;
//	for (beg; beg != end; beg++) {
//		if ( *beg == val) {
//			flag = 1;
//			break;
//		}
//	}
//	return flag;
//}


//void showlist( list<int> a) {
//	list<int>::iterator p1;
//	for (p1 = a.begin(); p1 != a.end(); p1++)
//		cout << *p1;
//	cout << endl;
//}

//void showdeque( deque<int> a) {
//	deque<int>::iterator p1;
//	for (p1 = a.begin(); p1 != a.end(); p1++) {
//		cout << *p1;
//	}
//		
//	cout << endl;
//}
//struct fn {
//	//重载运算符（）<>
//	void operator()(pair<string,double> m){
//		cout << "sunject:" << m.first << "  souece:" << m.second << endl;
//	}
//};

//void addfamily(map<string, vector<string>>& families, const string& familyname) {
//	families.insert(map<string, vector<string>>::value_type(familyname, 0));
//}
//void addchild(map<string, vector<string>>& families, const string& familyname,const string childname) {
//	families.insert(map<string, vector<string>>::value_type(familyname, families->second.push_back(childname));
//}

void hexreplace(string s,string oldVal,string newVal) {
	int p;
	while ((p = s.find(oldVal ) != string::npos)) {
		s.replace(p, oldVal.size(), newVal);
		p = p + newVal.size();
	}		
	cout << s;
}

int main()
{
	/*int v;
	vector<int> a ;
	cout << "please enter the arrey:";
	while (1) {
		cin >> v;
		a.push_back(v);
		if (cin.get() == '\n')break;
	}

	cout << "please enter the number you want select:" ;
	cin >> v;
	cout << searchVal(a.begin(), a.end(), v) << endl;*/

	//int v;

	//list<int> a = { 1,2,3,4,5,6 };
	//list<int>::iterator p1;
	//cout << a.size() << endl;
	//cout << a.empty() << endl;//检查列表是否为空
	//cout << a.front() << endl;
	//showlist(a);

	//cin >> v;
	//a.push_back(v);
	//showlist(a);

	//cin >> v;
	//a.push_front(v);
	//showlist(a);
	//cout << a.size() << endl;
	//cout << a.back()<<endl;
	//a.pop_back();
	//showlist(a);

	//deque<int> a;
	//deque<int> b;
	//list<int> m = { 1,2,3,4,5,6 };
	//
	//list<int>::iterator p1;
	//deque<int>::iterator p2;
	//for (p1 = m.begin(); p1 != m.end(); p1++) {
	//	int v = 0;
	//	if (v == 0) {
	//		a.push_back(*p1);
	//		v = 1;
	//	}
	//	else {
	//		b.push_back(*p1);
	//		v = 0;
	//	}
	//}
	//showdeque(a);
	//showdeque(b);
	/*for_each(a.begin(), a.end(), fn());*/
	//cout << endl;

	//map<string, double> subsource;
	//subsource["php"] = 91.5;
	//subsource["py"] = 95.5;
	//subsource["c"] = 99.5;
	//subsource.insert(map<string, double>::value_type("go",88.8));
	//map<string, double>::iterator m;
	//for (m = subsource.begin(); m != subsource.end(); m++)
	//	cout << "sunject:" << m->first << "  souece:" << m->second << endl;
	//cout << endl;
	//for_each(subsource.begin(), subsource.end(), fn());

	//m = subsource.find("c");
	//if (m != subsource.end()) {
	//	cout << m->second << endl;
	//}
	//else {
	//	cout << "not found" << endl;
	//}

	//
	//for (m = subsource.begin(); m != subsource.end();)
	//{
	//	if (m->second < 90.0) {
	//		m=subsource.erase(m);
	//	}
	//	else {
	//		cout << "sunject:" << m->first << "  souece:" << m->second << endl;
	//		m++;
	//	}
	//	
	//}

	/*map<string, vector<string>> families;
	addfamily (families, "张");
	addchild(families, "张", "三");*/

	//thru tho ->through though

	//string find,replace
	string s = "tho tho thu thru";
	/*int p = s.find("thu");
	cout << p << endl;
	string thu = "thu";
	s.replace(p, thu.size(), "through");
	cout << s << endl;*/
	hexreplace(s, "tho", "though");
}

// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单
// 调试程序: F5 或调试 >“开始调试”菜单

// 入门使用技巧: 
//   1. 使用解决方案资源管理器窗口添加/管理文件
//   2. 使用团队资源管理器窗口连接到源代码管理
//   3. 使用输出窗口查看生成输出和其他消息
//   4. 使用错误列表窗口查看错误
//   5. 转到“项目”>“添加新项”以创建新的代码文件，或转到“项目”>“添加现有项”以将现有代码文件添加到项目
//   6. 将来，若要再次打开此项目，请转到“文件”>“打开”>“项目”并选择 .sln 文件
